package com.gjy.leetcode;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * 217. 存在重复元素
 * 给你一个整数数组 nums 。如果任一值在数组中出现 至少两次 ，返回 true ；如果数组中每个元素互不相同，返回 false
 *
 * @author 宫静雨
 * @version 1.0
 * @since 2022-12-30 14:13:40
 */
public class A217 {

    @Test
    public void test1() {
        int[] nums = {1, 2, 3, 1};
        assertTrue(containsDuplicate(nums));
    }

    @Test
    public void test2() {
        int[] nums = {1, 2, 3, 4};
        assertFalse(containsDuplicate(nums));
    }

    @Test
    public void test3() {
        int[] nums = {1, 1, 1, 3, 3, 4, 3, 2, 4, 2};
        assertTrue(containsDuplicate(nums));
    }

    public boolean containsDuplicate(int[] nums) {
        /*Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        return set.size() != nums.length;*/
        int sum = 0;
        for (int num : nums) {
            sum = sum ^ num;
        }
        return false;
    }

    @Test
    public void test5() {
        System.out.println(2 & 3 & 1 & 0 & 2 & 5 & 3);
        System.out.println(3 ^ 0);
    }

    @Test
    public void test4() {
        System.out.println(3 ^ 3 ^ 0);
        System.out.println(3 | 3 | 0);
        System.out.println(1 | 2 | 3 | 2);
    }

    /**
     * 6 8
     * v1 = 0110
     * v2 = 1000
     * <p>
     * v1 = 1110
     * v2 = 0110
     * v1 = 1000
     */
    private static void swap(int[] arr, int var1, int var2) {
        arr[var1] = arr[var1] ^ arr[var2];
        arr[var2] = arr[var1] ^ arr[var2];
        arr[var1] = arr[var1] ^ arr[var2];
    }

}
